package com.wangdao.wechatmall.service.admin;

import com.github.pagehelper.PageInfo;
import com.wangdao.wechatmall.bean.bo.admin.FootprintListBO;
import com.wangdao.wechatmall.bean.pojo.Footprint;
import com.wangdao.wechatmall.bean.pojo.FootprintExample;
import com.wangdao.wechatmall.bean.vo.admin.BaseDataVO;
import com.wangdao.wechatmall.bean.vo.wx.WXFootprintVO;
import com.wangdao.wechatmall.mapper.FootprintMapper;
import com.wangdao.wechatmall.util.MyPageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZhangXiao on 2021/7/9
 */
@Service
public class FootprintListServiceImpl implements FootprintListSrevice {
    @Autowired
    FootprintMapper footprintMapper;

    @Override
    public BaseDataVO<Footprint> queryFootprintList(FootprintListBO footprintListBO) {
        MyPageHelper.startPage(footprintListBO);
        FootprintExample footprintExample = new FootprintExample();
        FootprintExample.Criteria criteria = footprintExample.createCriteria();

        Integer userId = footprintListBO.getUserId();
        Integer goodsId = footprintListBO.getGoodsId();
        if (userId != null && userId != ' ') {
            criteria.andUserIdEqualTo(userId);
        }
        if (goodsId != null && goodsId != ' ') {
            criteria.andGoodsIdEqualTo(goodsId);
        }

        footprintExample.setOrderByClause(footprintListBO.getSort() + " " + footprintListBO.getOrder());

        List<Footprint> footprints = footprintMapper.selectByExample(footprintExample);

        PageInfo<Footprint> footprintPageInfo = new PageInfo<>(footprints);
        long total = footprintPageInfo.getTotal();

        return BaseDataVO.ok(footprints, total);
    }
}
